package com.xxchat.entity.enums;

import com.xxchat.utils.StringTools;
import lombok.Getter;

/**
 * @author Waicc
 */

@Getter
public enum UserContactTypeEnum {
    USER(0, "U", "好友"),
    GROUP(1, "G", "群聊"),
    MYSELF(2, "M", "自己的群聊");

    private final Integer type;
    private final String prefix;
    private final String desc;

    // 根据名字查找枚举类：例如传 user 会匹配 USER枚举
    public static UserContactTypeEnum getByName(String name) {
        try {
            if (StringTools.isEmpty(name)) {
                return null;
            }
            return UserContactTypeEnum.valueOf(name.toUpperCase());
        } catch (Exception e) {
            return null;
        }
    }

    public static UserContactTypeEnum getByPrefix(String prefix) {
        try {
            if (StringTools.isEmpty(prefix) || prefix.trim().isEmpty()) {
                return null;
            }
            prefix = prefix.substring(0, 1).toUpperCase();
            for (UserContactTypeEnum type : UserContactTypeEnum.values()) {
                if (type.getPrefix().equals(prefix)) {
                    return type;
                }
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }

    UserContactTypeEnum(Integer type, String prefix, String desc) {
        this.type = type;
        this.prefix = prefix;
        this.desc = desc;
    }

}
